function getNowTime() {
	return ajax(`/getNowTime`, `get`, {});
}
/*
 * ajax请求
 * type为get || put || delete || post
 * params为JSON格式的参数
 */
function ajax(url, type, params) {
	var r = '';
	$.ajax({
		url : url,
		data : params,
		type : type,
		async : false,
		contentType : 'application/json;charset=utf-8',
		success : function(data) {
			r = data;
		},
		error : function(e) {
			alert(`url = ${url}, params = ${JSON.stringify(params)}, excption = ${JSON.stringify(e)}`);
		}
	});
	return r;
}
var conf = getConfig();
function reloadConf(){
	sessionStorage['conf'] = ``;
	getConfig();
}
//取得系统运行参数
function getConfig() {
	var conf = sessionStorage['conf'];
	if (conf == null || conf == '') {
		alert('浏览器尚未缓存conf');
		$.ajax({
			type : 'get',
			url : '/getConfig',
			async : false,
			success : function(data) {
				sessionStorage['conf'] = JSON.stringify(data);
				console.log(JSON.stringify(data));
			},
			error : function(xhr, textStatus, errorThrown) {
				alert('/getConfig请求配置信息异常, xhr = ' + JSON.stringify(xhr) + ', textStatus = ' + textStatus + ', errorThrown = ' + errorThrown);
			}
		});
	}
	return JSON.parse(sessionStorage['conf']);
}

//获取url后的参数值
function getUrlParam(key) {
	var href = window.location.href;
	//alert(href);
	var url = href.split('?');
	if (url.length <= 1) {
		return "";
	}
	var params = url[1].split('&');
	for (var i = 0; i < params.length; i++) {
		var param = params[i].split('=');
		if (key == param[0]) {
			return param[1];
		}
	}
}

function loadOneRow(data) {
	Object.keys(data).forEach(function(key) {
		$(`#${key}`).val(data[key]);
	})
}

$.fn.serializeObject = function() {
	var o = {};
	var a = this.serializeArray();
	$.each(a, function() {
		if (o[this.name] !== undefined) {
			if (!o[this.name].push) {
				o[this.name] = [o[this.name]];
			}
			o[this.name].push(this.value || '');
		} else {
			o[this.name] = this.value || '';
		}
	});
	return o;
};